package simple; /**
 * @projectName study-note
 * @package PACKAGE_NAME
 * @className PACKAGE_NAME.RemoveElement
 */

/**
 * RemoveElement
 * @description 移除元素
 * @author answer_wx
 * @date 2022/6/30 19:54
 * @version 1.0
 */
public class RemoveElement {
    public static int removeElement(int[] nums, int val) {
        int length = nums.length;
        int p1 = 0;
        for (int i = 0; i < length; i++) {
            if (val != nums[i]) {
                nums[p1++] = nums[i];
            }
        }
        return p1;
    }

    public static void main(String[] args) {
        int[] nums = {0, 1, 2, 2, 3, 0, 4, 2};
        System.out.println(removeElement(nums, 2));
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + ",");
        }
    }
}